﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFIDA.U9.SM.Ship;
using UFIDA.U9.PM.PO;
using UFSoft.UBF.PL;
using UFIDA.U9.PM.Rcv;
using UFIDA.U9.SM.RMA;
using UFIDA.U9.SM.SO;
using UFIDA.U9.CBO.SCM.Customer;
using UFIDA.U9.PR.PurchaseRequest;
using UFIDA.U9.AP.Payment;
using UFIDA.U9.CBO.FI.Enums;
using UFSoft.UBF.Util.DataAccess;
using System.Data;
using UFIDA.U9.AP.APBill;
using UFIDA.U9.AP.Enums;
using UFSoft.UBF.PL.Engine;
using UFIDA.U9.ER.LoanBill;
using UFIDA.U9.ER.Enums;
using ufida.u9.ait.openapi.utils;
using UFIDA.U9.ER.ReimburseBill;
using UFIDA.U9.YD.Cli.PlugBE.YD;


namespace UFIDA.U9.YD.Cli.PlugBE
{
    /// <summary>
    /// 运达项目
    /// 报销单
    /// 付款时,调用OA接口
    /// </summary>
    class YDReimburseBillHeadExtend : IEventSubscriber
    {
        //配置XX.sub.xml文件放置到portal/bin下，dll文件放置到portal/ApplicationServer/Libs下

        public void Notify(params object[] args)
        {
            if (args != null && args.Length != 0 && args[0] is EntityEvent)
            {
                BusinessEntity.EntityKey key = ((EntityEvent)args[0]).EntityKey;
                ReimburseBillHead be = key.GetEntity() as ReimburseBillHead;
                if (be == null)
                    return;

                //来源系统为空,不用回写
                if (string.IsNullOrEmpty(be.DescFlexField.PrivateDescSeg16))
                    return;

                if (be.DocStatus== ReimburseDocStatusEnum.Closed
                    &&be.OriginalData.DocStatus != ReimburseDocStatusEnum.Closed)
                {
                    //确认付款 时
                    OARest.PayConfirm(be.DescFlexField.PrivateDescSeg17, be.DocNo);
                }
                else if(be.DocStatus != ReimburseDocStatusEnum.Closed
                    && be.OriginalData.DocStatus == ReimburseDocStatusEnum.Closed)
                {
                    //取消确认 时
                    OARest.PayUnConfirm(be.DescFlexField.PrivateDescSeg17, be.DocNo);
                }
            }
        }
    }
}
